<#macro multiChooseDlg id title url>

<div class="modal " id="${id}Dlg" tabindex="-1" role="dialog" aria-labelledby="${id}DlgTitle" aria-hidden="true">
  <div class="modal-dialog" style="width:700px">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="${id}DlgTitle">${title}</h4>
        <div class="modal-body" id="${id}ListContainer">
        	
      	</div>
      	<div class="modal-footer">
      	<button type="button" class="btn btn-primary" id="btn-${id}AddSure">是</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">否</button>        
      </div>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script type="text/javascript">
$('#${id}ListContainer').on("click",'tr',function(){
	var radio=$('input[name=selectId]',this);
	radio.prop("checked",!radio.prop("checked"));
});
var _${id}={
	selectedIds:"",
	selectedNames:"",
	showMappingMultiChooseDlg:function(selectedIds,selectedNames)
	{
		$.get('${url}&pageSize=5',{},_${id}.multiAfterLoadData,'html');
		$('#${id}Dlg').modal('show');
		this.selectedIds=selectedIds;	
		this.selectedNames=selectedNames;
	},
	multiAfterLoadData:function(data)
	{
		$('#${id}ListContainer').empty();
		$('#${id}ListContainer').append(data);
		if(_${id}.selectedIds)
		{
			$.each($('#${id}ListContainer [name="selectId"]'),function(index,ele){
				if((","+_${id}.selectedIds+",").indexOf(","+ele.value+",")!=-1)
					$(ele).prop("checked",true);				
			});
		}
		//$('#${id}Dlg').on('hidden.bs.modal', function (e) {
		//		$('#${id}ListContainer').empty();
		//});	
	},
	toPage:function(params)
	{
		_${id}._getData();
		$.get('${url}',params,_${id}.multiAfterLoadData,'html'); 	  	
	},
	_getData:function()
	{
		var selectedId_temp=_${id}.selectedIds?","+_${id}.selectedIds+",":",";
		var selectedNames_temp=_${id}.selectedNames?","+_${id}.selectedNames+",":",";
		var eles=$('#${id}ListContainer [name="selectId"]');
		$.each(eles,function(index,ele){
			if($(ele).prop("checked"))
			{
				if(selectedId_temp.indexOf(ele.value)==-1)
				{
					selectedId_temp+=ele.value+",";
					selectedNames_temp+=$(ele).parent().siblings()[0].innerText+",";
				}
			}
			else
			{
				selectedId_temp=selectedId_temp.replace(new RegExp(ele.value+",","g"),"");
				selectedNames_temp=selectedNames_temp.replace(new RegExp($(ele).parent().siblings()[0].innerText+",","g"),"");
			}	
		});
		if(selectedId_temp.length>2)
		{
			_${id}.selectedIds=selectedId_temp.substring(1,selectedId_temp.length-1);
			_${id}.selectedNames=selectedNames_temp.substring(1,selectedNames_temp.length-1);
		}	
		else
		{
			_${id}.selectedIds="";
			_${id}.selectedNames="";
		}	
	},
	getData:function()
	{
		_${id}._getData();
		$('#${id}Dlg').modal('hide');		
		return {ids:_${id}.selectedIds,names:_${id}.selectedNames};
	}
}
</script>

</#macro>